﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySite.Helper;

namespace MySite.SinaWeiBo
{
    public class IOAuthBase
    {
        /// <summary>
        /// 键值对用来存取querystring的name和value
        /// </summary>
        public class QueryParameter
        {
            public QueryParameter(string name, string value)
            {
                Name = name;
                Value = value;
            }
            public string Name { get; private set; }
            public string Value { get; private set; }
        }

        /// <summary>
        /// 显示的构造函数
        /// </summary>
        public IOAuthBase()
        {

        }

        /// <summary>
        /// 把QueryParameterList转换为QueryString
        /// </summary>
        /// <param name="paras"></param>
        /// <returns></returns>
        public string QueryParameterList2PostData(IList<QueryParameter> paras)
        {
            StringBuilder sb = new StringBuilder();

            foreach (QueryParameter item in paras)
            {
                if (sb.Length > 0)
                {
                    sb.Append("&");
                }

                sb.AppendFormat("{0}={1}", item.Name, Utility.UrlEncode(item.Value));
            }

            return sb.ToString();
        }
    }
}
